package com.frejoys.common.util;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.AES;
import com.frejoys.common.config.ValueConfig;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;


@Component
@RequiredArgsConstructor
public class EncryptUtil {

    private final ValueConfig valueConfig;

    // private E ncryptUtil() {}
    //
    // private static volatile EncryptUtil encryptUtil;

    // app加解密数据
    public static AES appAes;

    // admin加解密数据
    public static AES adminAes;

    // store加解密数据
    public static AES storeAes;

    @PostConstruct
    private void init() {

        appAes = new AES(Mode.CBC, Padding.PKCS5Padding, valueConfig.getAppAesKey().getBytes(), valueConfig.getAppAesIv().getBytes());

        adminAes = new AES(Mode.CBC, Padding.PKCS5Padding, valueConfig.getAdminAesKey().getBytes(), valueConfig.getAdminAesIv().getBytes());

        storeAes = new AES(Mode.CBC, Padding.PKCS5Padding, valueConfig.getStoreAesKey().getBytes(), valueConfig.getStoreAesIv().getBytes());

    }

}
